import java.util.HashMap;
import java.util.Scanner;
import java.util.zip.CheckedInputStream;
 class ListNode {
     int val;
     ListNode next;
     ListNode() {}
     ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
public class Test {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串s1:");
        String s1 = scanner.nextLine();
        System.out.println("请输入字符串s2:");
        String s2 = scanner.nextLine();
        int m = s1.length();
        int n = s2.length();
        int cost=0;
        int i=0;
        int j=0;
        int s=1;
        while(i<m||j<n){
            if(i>=m){
                cost=cost+j-1;
                j++;
            }else if(j>=n){
                cost=cost+i;
                j=0;
            }else if(s1.charAt(i)==s2.charAt(j)){
                i++;
                j++;
            }

        }
        System.out.println(cost);
    }
    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串s1:");
        String s1 = scanner.nextLine();
        System.out.println("请输入字符串s2:");
        String s2 = scanner.nextLine();

        int m = s1.length();
        int n = s2.length();
        int[][] dp = new int[m + 1][n + 1];

        // 初始化dp数组
        for (int i = 0; i <= m; i++) {
            dp[i][0] = i;
        }
        for (int j = 0; j <= n; j++) {
            dp[0][j] = j;
        }

        // 填充dp数组
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                if (s1.charAt(i - 1) == s2.charAt(j - 1)) {
                    dp[i][j] = dp[i - 1][j - 1];
                } else {
                    dp[i][j] = Math.min(dp[i - 1][j] + i, Math.min(dp[i][j - 1] + j, dp[i - 1][j - 1] + i));
                }
            }
        }

        System.out.println("将字符串s1变成s2所需的最小代价是: " + dp[m][n]);

        scanner.close();

    }
    public static void main4(String[] args) {
        Scanner scan=new Scanner(System.in);
        int milk=scan.nextInt();
        int tea=scan.nextInt();
        int milkTea1=(milk-tea)/10;
        int milkTea2=(3*tea-milk)/20;
        if(milkTea1>=0&&milkTea2>=0&&(milk-tea)%10==0&&(3*tea-milk)%20==0){
            System.out.println(milkTea1+" "+milkTea2);
        }else {
            System.out.println(-1);
        }

    }
    public static void main3(String[] args) {
        System.out.println("c"+1);
        float f=202;
        int a='a';
        float b='b';

        System.out.println(f);
    }
    public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        if (l1 == null && l2 == null) {
            return null;
        }
        if (l1.next == null && l2.next == null) {
            int e = l1.val + l2.val;
            ListNode head = new ListNode(e);
            return head;
        }
        ListNode phead = null;
        ListNode p3 = null;
        ListNode p1 = l1;
        ListNode p2 = l2;
        ListNode p4 = null;
        ListNode p5 = null;
        while (p1 != null && p2 != null) {
            int value = p1.val + p2.val;
            if (value < 10) {
                if (phead == null) {
                    phead = new ListNode(value);
                    p3 = phead;
                    p4 = p1;
                    p5 = p2;
                    p1 = p1.next;
                    p2 = p2.next;
                } else {
                    p3.next = new ListNode(value);
                    p3 = p3.next;
                    p4 = p1;
                    p5 = p2;
                    p1 = p1.next;
                    p2 = p2.next;
                }
            } else {
                if (phead == null) {
                    phead = new ListNode(value % 10);
                    p3 = phead;
                    p4 = p1;
                    p5 = p2;
                    p1 = p1.next;
                    p2 = p2.next;
                    p1.val = p1.val + 1;
                } else {
                    p3.next = new ListNode(value % 10);
                    p3 = p3.next;
                    p4 = p1;
                    p5 = p2;
                    p1 = p1.next;
                    p2 = p2.next;
                    p1.val = p1.val + 1;
                }
            }

        }
        int value2 = p4.val + p5.val;
        while (p1 != null) {
            if (value2 < 10) {
                p3.next = new ListNode(p1.val);
                p3 = p3.next;
                value2 = (value2 + p1.val) / 10;
                p1 = p1.next;

            } else {
                p3.next = new ListNode((p1.val + value2 / 10 % 10) % 10);
                value2 = p1.val + value2 / 10 % 10;
                p1 = p1.next;
                p3 = p3.next;
            }
        }

        while (p2 != null) {
            if (value2 < 10) {
                p3.next = new ListNode(p2.val);
                p3 = p3.next;
                value2 = (value2 + p2.val) / 10;
                p2 = p2.next;
            } else {
                p3.next = new ListNode((p2.val + value2 / 10 % 10) % 10);
                value2 = p2.val + value2 / 10 % 10;
                p2 = p2.next;
                p3 = p3.next;
            }
        }

        return phead;
    }
    public static void main2(String[] args) {
        ListNode l1=new ListNode(9);
        l1.next=new ListNode(9);
        l1=l1.next;
        l1.next=new ListNode(9);
        l1=l1.next;
        l1.next=new ListNode(9);
        l1=l1.next;
        l1.next=new ListNode(9);
        l1=l1.next;
        l1.next=new ListNode(9);
        l1=l1.next;
        l1.next=new ListNode(9);
        l1=l1.next;
        ListNode l2=new ListNode(9);
        l2.next=new ListNode(9);
        l2=l2.next;
        l2.next=new ListNode(9);
        l2=l2.next;
        l2.next=new ListNode(9);
        l2=l2.next;
        //System.out.println(addTwoNumbers(l1, l2));
    }
    public static boolean  CheckPermutation(String s1, String s2) {
        HashMap<Character,Integer> map=new HashMap<>();
        for(int i=0;i<s1.length();i++){
            char ch=s1.charAt(i);
            if(map.get(ch)==null){
                map.put(ch,1);
            }else{
                map.put(ch,map.get(ch)+1);
            }
        }
        HashMap<Character,Integer> map2=new HashMap<>();
        for(int i=0;i<s2.length();i++){
            char ch=s2.charAt(i);
            if(map2.get(ch)==null){
                map2.put(ch,1);
            }else{
                map2.put(ch,map2.get(ch)+1);
            }
        }
        for(int i=0;i<s2.length();i++){
            char ch=s2.charAt(i);
            if(!map.containsKey(ch)){
                return false;
            }else{
                if(map2.get(ch)!=map.get(ch)){
                    return false;
                }
            }
        }
        return true;
    }

    public static void main1(String[] args) {

        Scanner scan =new Scanner(System.in);
        String s1=scan.nextLine();
        String s2=scan.nextLine();
        Boolean flg=CheckPermutation(s1,s2);
        System.out.println(flg);
    }

//    public static int x;
//    public static void main(String []args)
//    {
//        System. out. println("Value is" + x);
//    }

}
